*** One-Child Policy, Marriage Distortion, and Welfare Loss ***
*** by Wei Huang, Yinghao Pan and Yi Zhou ***

clear all 
set more off
set scheme s1color
cap log close 
graph set window fontface "Times New Roman"

set niceness 10
gl MAIN = "F:\Dropbox"

gl path1 = "$MAIN/Census"
gl path2 = "$MAIN/Marriage/Working_data"
gl path3 = "$MAIN/Marriage/Restat/dataverse_files/Results" 
gl path4 = "$MAIN/Marriage/Restat/dataverse_files/Graphics" 
gl CONTROL = " year_birth sex#age urban_hk prov_hk##c.(year_birth ) "


use "$path2/unmarried", clear
keep if relation == 0 | relation == 1 | relation == 2 | relation == 6 

merge 1:1 wave area hhid name relation using "$path2/min_marr_policy", keepusing(marry_1 marry_2 marry_3) nogen


drop if mi(hktype)
replace urban = hktype == 1 
su age 

gen han = 1- minority 

replace unmarried = unmarried * 100 
gen unmarr_25 = marr_age > 25 if !mi(marr_age)
replace unmarr_25 = 1 if unmarried == 100 
replace unmarr_25 = unmarr_25 *100 

gen urban_hk = hktype == 2 


gen marry_9 = unmarried == 0 & (mi(marry_1) & mi(marry_2) & mi( marry_3))

recode marry_1 marry_2 marry_3 (. = 0) 

gen HH = marry_1 * 100 
gen HM = marry_2 * 100 
gen MM = marry_3 * 100 
gen Other = marry_9 * 100 
gen HOMO = HH + MM
su HOMO

keep if age <= 55 
keep if age > 25
keep if year_birth <= 1980 
keep if Other == 0 





cap erase "$path3/marriage_fine_prov.xls"
cap erase "$path3/marriage_fine_prov.txt"

*** Columns 1-2 of Table 1 & Appendix Table A3 ***

foreach y_var in  "unmarried" "HOMO" "HM"  {
foreach policy in "1" "mino_policy == 1"  "mino_policy == 0"  {
foreach eth in  "han" "han == 0"{
preserve 
keep if  `policy' & `eth'


reghdfe `y_var' fine_16_25 [aw = aw], a($CONTROL)  cluster(prov_hk)
su `y_var' [aw = aw]
outreg2 using "$path3/marriage_fine_prov.xls", append bracket addstat(Y, `r(mean)') ctit(`policy' & `eth') keep(fine_16_25)

restore


}
}
}

*** Columns 3-4 of Table 1 ***


cap erase "$path3/marriage_fine_cond_prov.xls"
cap erase "$path3/marriage_fine_cond_prov.txt"


foreach policy in "1" "mino_policy == 1"  "mino_policy == 0"  {
foreach eth in  "han" "han == 0"{
preserve 
keep if unmarried == 0 & `policy' & `eth'

reghdfe HM fine_16_25 [aw = aw], a($CONTROL)  cluster(prov_hk)
su HM [aw = aw]
outreg2 using "$path3/marriage_fine_cond_prov.xls", append bracket addstat(Y, `r(mean)') ctit(`policy' & `eth') keep(fine_16_25)

restore


}
}




*** Appendix Figure A10 (a)-(d) ***

preserve 

reghdfe unmarried if han [aw = aw], a( year_birth sex#age urban_hk prov_hk##c.(year_birth )) res(unmarried_han_res)
reghdfe fine_16_25 if han [aw = aw], a( year_birth sex#age urban_hk prov_hk##c.(year_birth )) res(fine_han_res)
reghdfe unmarried if han == 0 [aw = aw], a( year_birth sex#age urban_hk prov_hk##c.(year_birth ) ) res(unmarried_mino_res)
reghdfe fine_16_25 if han == 0 [aw = aw], a( year_birth sex#age urban_hk prov_hk##c.(year_birth ) ) res(fine_mino_res)

reg unmarried_han_res fine_han_res if han, cluster(prov_hk)
local beta = string(_b[fine_han_res],"%9.3f")
local cons = string(_b[_cons],"%9.3f")
local se = string(_se[fine_han_res], "%9.3f")
binscatter unmarried_han_res fine_han_res if han [aw = aw], n(30)  ylabel(-3(1)3) xlabel(-0.8(0.2)0.8) text(-2 0 "Y =  `beta'X `cons'" "(`se')" ) ///
xtit("Fines at ages 16-25, Residuals") ytit("Unmarried, Residuals")
gr export "$path4/unmarried_han_res.pdf",replace 

reg unmarried_mino_res fine_mino_res if han ==0, cluster(prov_hk)
local beta = string(_b[fine_mino_res],"%9.3f")
local cons = string(_b[_cons],"%9.3f")
local se = string(_se[fine_mino_res], "%9.3f")
binscatter unmarried_mino_res fine_mino_res if han ==0 [aw = aw], n(30) ylabel(-3(1)3)  xlabel(-0.8(0.2)0.8) text(-2 0 "Y =  `beta'X `cons'" "(`se')" ) ///
xtit("Fines at ages 16-25, Residuals") ytit("Unmarried, Residuals")
gr export "$path4/unmarried_mino_res.pdf",replace 

restore 

preserve

reghdfe HOMO if mino_policy == 1  & unmarried == 0 [aw = aw], a( year_birth sex#age urban_hk prov_hk##c.(year_birth )) res(HOMO_treat_res)
reghdfe fine_16_25 if  mino_policy == 1  & unmarried == 0 [aw = aw], a( year_birth sex#age urban_hk prov_hk##c.(year_birth )) res(fine_treat_res)

reghdfe HOMO if mino_policy == 0 & unmarried == 0 [aw = aw], a( year_birth sex#age urban_hk prov_hk##c.(year_birth ) ) res(HOMO_cntl_res)
reghdfe fine_16_25 if mino_policy == 0  & unmarried == 0 [aw = aw], a( year_birth sex#age urban_hk prov_hk##c.(year_birth ) ) res(fine_cntl_res)

reg HOMO_treat_res fine_treat_res if mino_policy == 1 & unmarried == 0 [aw = aw], cluster(prov_hk)
local beta = string(_b[fine_treat_res],"%9.3f")
local cons = string(_b[_cons],"%9.3f")
local se = string(_se[fine_treat_res], "%9.3f")
binscatter HOMO_treat_res fine_treat_res if mino_policy == 1 & unmarried == 0 [aw = aw] , n(30) xlabel(-0.8(0.2)0.8) ylabel(-1.5(0.5)1.5) ///
text(-.5 0 "Y =  `beta'X + `cons'" "(`se')" ) xtit("Fines at ages 16-25, Residuals") ytit("Intra-ethnic marriage (%), Residuals")
gr export "$path4/homo_treat_res.pdf",replace 

reg HOMO_cntl_res fine_cntl_res if mino_policy == 0 & unmarried == 0  [aw = aw], cluster(prov_hk)
local beta = string(_b[fine_cntl_res],"%9.3f")
local cons = string(_b[_cons],"%9.3f")
local se = string(_se[fine_cntl_res], "%9.3f")
binscatter HOMO_cntl_res fine_cntl_res if mino_policy == 0 & unmarried == 0 [aw = aw] , n(30) xlabel(-0.8(0.2)0.8) ylabel(-1.5(0.5)1.5) ///
text(-.5 0 "Y =  `beta'X `cons'" "(`se')" ) xtit("Fines at ages 16-25, Residuals") ytit("Intra-ethnic marriage (%), Residuals")
gr export "$path4/homo_cntl_res.pdf",replace 


restore 




